package com.tjian.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import static android.content.Context.CONNECTIVITY_SERVICE;

/**
 * @author
 */

public class NetUtil
{
    /*public static String convertStreamToString(InputStream is)
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();
        String line = null;
        try
        {
            while ((line = reader.readLine()) != null)
            {
                sb.append(line);
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                is.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }*/

    //检查网络连接并且提醒打开网络连接；
    public static void checkNetworkAndRemindingOpenNetwork(Context context)
    {
        //ConnectivityManager connManager = (ConnectivityManager) this.getSystemService(CONNECTIVITY_SERVICE);
        ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
        if (!connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected() &&
                !connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected())
        {
            Toast.makeText(context, "目前网络未开通，请打开网络连接_20170126_230704", Toast.LENGTH_LONG).show();
        }
    }


}
